package com.deyuanyun.pic.pbf.controller;

import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.deyuanyun.pic.common.dto.PageJsonBean;
import com.deyuanyun.pic.common.tool.JXL;
import com.deyuanyun.pic.common.util.MyCollectionUtil;
import com.deyuanyun.pic.common.util.StringUtils;
import com.deyuanyun.pic.common.util.ajax.AjaxSupport;
import com.deyuanyun.pic.common.util.poi.ExcelUtil;
import com.deyuanyun.pic.common.util.poi.ReadExcel;
import com.deyuanyun.pic.common.util.web.Asserts;
import com.deyuanyun.pic.common.util.web.WebUtil;
import com.deyuanyun.pic.common.validator.imlclass.BeanValidateUtil;
import com.deyuanyun.pic.common.validator.imlclass.VResult;
import com.deyuanyun.pic.pbf.controller.dto.DefectInfoDTO;
import com.deyuanyun.pic.pbf.controller.dto.DefectSuggestVO;
import com.deyuanyun.pic.pbf.controller.dto.NearbyLocationDTO;
import com.deyuanyun.pic.pbf.controller.dto.RepairDefectInfoExcelVO;
import com.deyuanyun.pic.pbf.controller.dto.RepairTaskDTO;
import com.deyuanyun.pic.pbf.controller.dto.RepairTaskQueryVO;
import com.deyuanyun.pic.pbf.domain.RepairTask;
import com.deyuanyun.pic.pbf.domain.RepairTaskWorkload;
import com.deyuanyun.pic.pbf.enumeration.DefectStateEnum;
import com.deyuanyun.pic.pbf.enumeration.ImgCustomType;
import com.deyuanyun.pic.pbf.enumeration.RepairTaskStatedEnum;
import com.deyuanyun.pic.pbf.service.DefectInfoService;
import com.deyuanyun.pic.pbf.service.RepairTaskService;
import com.deyuanyun.pic.pipe.controller.BaseController;
import com.deyuanyun.pic.pipe.domain.CenterLine;
import com.deyuanyun.pic.pipe.domain.MapValveRoomObj;
import com.deyuanyun.pic.pipe.service.PipeCenterLineService;
import com.deyuanyun.pic.pipe.service.PipeValveRoomService;
import com.deyuanyun.pic.settings.domain.base.Attachment;
import com.deyuanyun.pic.settings.domain.util.DomainCollectionsUtil;
import com.deyuanyun.pic.settings.service.base.AttachmentService;
import com.deyuanyun.pic.settings.util.DownExcelUtil;

/**
 *  维修任务Controller
 *
 * @author ChenKui
 * @date 2016-06-16
 */
@Controller
@RequestMapping("/pbf/RepairTask")
public class RepairTaskController extends BaseController{

    private @Autowired PipeCenterLineService pipeCenterLineService;//管道中心线
    private @Autowired RepairTaskService repairTaskService;//缺陷任务相关
    private @Autowired DefectInfoService defectInfoService;//缺陷点信息相关
    private @Autowired PipeValveRoomService pipeValveRoomService;//
    private @Autowired AttachmentService attachmentService;

    //进入维修任务列表页面
    @RequestMapping("/init.html")
    public ModelAndView init(ModelMap model) {
        //维修任务状态
        model.addAttribute("repairTaskStateds", RepairTaskStatedEnum.values());
        //AjaxSupport.sendSuccessText("success", model.asMap());
        return forword("/pbf/repairManage/repairList", model);
    }

    //进入创建维修任务页面
    @RequestMapping("/initCreate.html")
    public ModelAndView initCreate(ModelMap model) {
        
        //AjaxSupport.sendSuccessText("success", model.asMap());
        return forword("/pbf/repairManage/repairCreate", model);
    }

    //进入缺陷点详情界面
    @RequestMapping("/initDetail.html")
    public ModelAndView initDetail(ModelMap model) {
        
        //AjaxSupport.sendSuccessText("success", model.asMap());
        return forword("/pbf/repairManage/repairDetails", model);
    }

    //初始化进去 缺陷点附近的 定位点信息
    @RequestMapping("/initNearbyLocation.html")
    public ModelAndView initNearbyLocation(ModelMap model) {
        
        //AjaxSupport.sendSuccessText("success", model.asMap());
        return forword("/pbf/repairManage/repairLocationMap", model);
    }
    

    //进入维修任务条件查询地图
    @RequestMapping("/initRepairTaskGIS.html")
    public ModelAndView initRepairTaskGIS(ModelMap model) {
        
        //AjaxSupport.sendSuccessText("success", model.asMap());
        return forword("/pbf/repairManage/repairTaskMap", model);
    }
    
    /**
     * 查询维修任务列表
     * 
     * @param repairTaskQuery
     * @param model
     */
    @RequestMapping("/queryRepairTaskList.json")
    @ResponseBody
    public void queryRepairTaskList(RepairTaskQueryVO repairTaskQuery,ModelMap model) {
        PageJsonBean jsonBean = new PageJsonBean();
        List<RepairTaskDTO> repairTaskList = repairTaskService.queryRepairTaskList(repairTaskQuery);
        //model.addAttribute("repairTaskList", repairTaskList);
        jsonBean.setList(repairTaskList);
        AjaxSupport.sendSuccessText("success", jsonBean);
        //return forword("/pbf/queryRepairTaskList.jsp", model);
    }

    /**
     * 查询某一任务的详情（含具体缺陷点）
     * 
     * @param repairTaskId
     * @param model
     * @return
     */
    @RequestMapping("/queryDetail.json")
    @ResponseBody
    public void queryDetail(@RequestParam("repairTaskId") String repairTaskId,ModelMap model) {
        
        //查询维修任务的详情信息
        RepairTaskQueryVO repairTaskVO = new RepairTaskQueryVO();
        repairTaskVO.setRepairTaskIds(new String[]{repairTaskId});
        List<RepairTaskDTO> repairTaskList = repairTaskService.queryRepairTaskList(repairTaskVO);
        Asserts.assertTrue(repairTaskList != null && !repairTaskList.isEmpty(), "没有找到对应维修任务记录");
        
        RepairTaskDTO repairTask = repairTaskList.get(0);
        model.addAttribute("repairTask", repairTask);
        
        PageJsonBean jsonBean = new PageJsonBean();
        //查询维修任务对应的缺陷点
        List<DefectInfoDTO> defectInfoList = repairTaskService.queryDefectInfoList(new String[]{repairTaskId});
        for (int i = 0; i < defectInfoList.size(); i++) {
            DefectInfoDTO defectInfoDTO = defectInfoList.get(i);
            String businessId = defectInfoDTO.getDefectId();
            List<Attachment> l = attachmentService.queryAttachment(businessId);
            defectInfoDTO.setAttachmentList(l);
        }
        jsonBean.setList(defectInfoList);
        model.addAttribute("defectInfoList", jsonBean);
        
        //返回工作量
        RepairTaskWorkload repairTaskWorkload = repairTaskService.queryRepairTaskWorkload(repairTaskId);
        model.addAttribute("repairTaskWorkload", repairTaskWorkload);
        
        //获取管道的中心线GISID
        String pipeLineId = repairTask.getPipeLineId();
        if(StringUtils.isNotEmpty(pipeLineId)){
            CenterLine pipeLineCenterLine = pipeCenterLineService.getCenterLineByLineId(pipeLineId);
            model.addAttribute("pipeLineCenterLine", pipeLineCenterLine);
        }

        List<MapValveRoomObj> mapValveRoomObjList = pipeValveRoomService.queryMapValveRoomObj(pipeLineId);
        String[] gisIds = DomainCollectionsUtil.toOneFieldValues(mapValveRoomObjList, "gisId");
        model.addAttribute("valveRoomGisIds", gisIds);
        AjaxSupport.sendSuccessText("success", model);
        //return forword("/pbf/queryDetail", model);
    }


    /**
     * 根据条件查询维修任务的GISID，在地图那个地方需要。
     * 
     * @param repairTaskQuery
     * @param model
     */
    @RequestMapping("/queryRepairTaskGISID.json")
    @ResponseBody
    public void queryRepairTaskGISID(RepairTaskQueryVO repairTaskQuery,ModelMap model) {
        String[] repairTaskIds_Q = repairTaskQuery.getRepairTaskIds();
        Set<String> pipeLineIdSet = new HashSet<String>();
        List<DefectInfoDTO> defectInfoList;
        if(repairTaskIds_Q == null || repairTaskIds_Q.length == 0){//如果客户端没有传递任务编号，就一条也不查询。
            defectInfoList = Collections.emptyList();
        }else{
            List<RepairTaskDTO> repairTaskList = repairTaskService.queryRepairTaskList(repairTaskQuery);
            if(repairTaskList != null && !repairTaskList.isEmpty()){
                
                String[] repairTaskIds = DomainCollectionsUtil.toOneFieldValues(repairTaskList, "repairTaskId");
                String[] pipeLineIds = DomainCollectionsUtil.toOneFieldValues(repairTaskList, "pipeLineId");
                for (int i = 0; i < pipeLineIds.length; i++) {
                    pipeLineIdSet.add(pipeLineIds[i]);
                }
                defectInfoList = repairTaskService.queryDefectInfoList(repairTaskIds);
                
            }else{
                defectInfoList = Collections.emptyList();
            }
        }
        model.addAttribute("defectInfoList", defectInfoList);
        
        //获取管道的中心线GISID
        //String pipeLineId = repairTaskQuery.getPipeLineId();
        List<String> pipeLineGisidList = new ArrayList<String>(pipeLineIdSet.size());
        Set<String> valveRoomGisIdSet = new HashSet<String>(pipeLineIdSet.size());
        for (String pipeLineId : pipeLineIdSet) {
            if(StringUtils.isNotEmpty(pipeLineId)){
                CenterLine pipeLineCenterLine = pipeCenterLineService.getCenterLineByLineId(pipeLineId);
                pipeLineGisidList.add(pipeLineCenterLine.getGisId());
                
                List<MapValveRoomObj> mapValveRoomObjList = pipeValveRoomService.queryMapValveRoomObj(pipeLineId);
                String[] gisIds = DomainCollectionsUtil.toOneFieldValues(mapValveRoomObjList, "gisId");
                for (int i = 0; i < gisIds.length; i++) {
                    valveRoomGisIdSet.add(gisIds[i]);    
                }
            }
        }
        model.addAttribute("pipeLineGisidList", pipeLineGisidList);
        model.addAttribute("valveRoomGisIdList", valveRoomGisIdSet);
        //MapValveRoomObjMapper
        
        //gisid
        //pipeLineId
        //pipeSegmentId
        
        //jsonBean.setList(repairTaskList);
        AjaxSupport.sendSuccessText("success", model);
        //return forword("/pbf/queryRepairTaskList.jsp", model);
    }
    

    /**
     * 查询某一个缺陷点附近的定位点信息
     * 参数：
     * defectInfoId=缺陷点编号
     * 返回：
     * defectInfo缺陷点基本信息
     * 
       nearbyLocation：定位位置信息
        {
        String typeName;//定位点种类（Mark、环焊缝、弯头）
        Number mileage;//绝对距离
        Number relativeMileage;//相对距离
        String fromCrossClock;//上游交汇时钟位置
        String toCrossClock;//下游交汇时钟位置
        String gisId;//地图GIS
        }
     * 
     * @param repairTask
     * @param model
     */
    @RequestMapping("/queryNearbyLocationByMileage.json")
    @ResponseBody
    public void queryNearbyLocationByMileage(
            @RequestParam("defectInfoId")String defectInfoId
            ,ModelMap model) {
        
        DefectInfoDTO defectInfo = defectInfoService.queryDefectInfoDTO(defectInfoId);
        String pipeLineId = defectInfo.getPipeId();//管道编号
        BigDecimal mileage = defectInfo.getMileage();//绝对距离
        
        List<NearbyLocationDTO> nearbyLocationList = defectInfoService.queryNearbyLocationByMileage(pipeLineId, mileage);
        //把缺陷点自身加入进去。
        NearbyLocationDTO nearbyLocation = new NearbyLocationDTO();//缺陷点自身
        nearbyLocation.setTypeName("目标点");
        nearbyLocation.setMileage(defectInfo.getMileage());
        nearbyLocation.setRelativeMileage(new BigDecimal(0));
        nearbyLocation.setGisId(defectInfo.getGisId());
        nearbyLocationList.add(0, nearbyLocation);//把缺陷点自身加入进去，加在最前面。
        

        //获取管道的中心线GISID
        //String pipeLineId = repairTaskQuery.getPipeLineId();
        if(StringUtils.isNotEmpty(pipeLineId)){
            CenterLine pipeLineCenterLine = pipeCenterLineService.getCenterLineByLineId(pipeLineId);
            model.addAttribute("pipeLineCenterLine", pipeLineCenterLine);
        }

        List<MapValveRoomObj> mapValveRoomObjList = pipeValveRoomService.queryMapValveRoomObj(pipeLineId);
        String[] gisIds = DomainCollectionsUtil.toOneFieldValues(mapValveRoomObjList, "gisId");
        model.addAttribute("valveRoomGisIds", gisIds);
        
        model.addAttribute("defectInfo", defectInfo);
        model.addAttribute("nearbyLocation", nearbyLocationList);
        //jsonBean.setList(repairTaskList);
        AjaxSupport.sendSuccessText("success", model);
        //return forword("/pbf/queryRepairTaskList.jsp", model);
    }
    
    
    
    /**
     * 导出Excel
     * @param repairTask
     * @param model
     * @param response
     * @throws IOException
     */
    @RequestMapping("/toExcel.json")
    @ResponseBody
    public void toExcel(RepairTaskQueryVO repairTask,ModelMap model,HttpServletResponse response) throws IOException {
        
        //查询维修任务的详情信息
        List<RepairTaskDTO> repairTaskList = repairTaskService.queryRepairTaskList(repairTask);
        
        String filePath = "/template/excl/pbf/repairtask_template.xlsx";
        List<String[]> listSheet = JXL.toListFormVO(repairTaskList, "yyyy-MM-dd");
        Integer beginRow = 3;
        Workbook workbook = ExcelUtil.initWorkbook(filePath, listSheet, beginRow - 1);//-1是因为删除了头部一行
        String ydm = StringUtils.convertDateToString(new Date(), "yyyyMMdd");
        DownExcelUtil.fillWorkbookHead(workbook);
        WebUtil.setDownHeader("缺陷维修项目列表" + ydm + ".xlsx");
        workbook.write(response.getOutputStream());
        
    }


    /**
     * 上传Excel，第一步。
     * 
     * @param repairTask
     * @param defectInfoExcelFile
     */
    @RequestMapping("/createOrUpdate1.json")
    @ResponseBody
    public void createOrUpdate1(RepairTask repairTask
            ,@RequestParam(value = "defectInfoExcelFile",required = false) MultipartFile defectInfoExcelFile
            ,ModelMap model
            ,HttpServletRequest request) {
        
        //Asserts.assertTrue(!ObjectUtil.isEmptyAll(defectInfoExcelFile),"附件不能为空");
        if(defectInfoExcelFile != null && !defectInfoExcelFile.isEmpty()){
            
            List<RepairDefectInfoExcelVO> rediExcelList;
            VResult b;
            InputStream is = null;
            try{
                is = defectInfoExcelFile.getInputStream();
                //从Excel中读取进来
                rediExcelList = ReadExcel.readExcle(RepairDefectInfoExcelVO.class,is,4);

                //哎，从没见过写公共方法抛这么多莫名其妙的Exception出来的。
                //吐槽：读Excel出现异常可以理解，但是删除空白行也抛显示异常是什么意思？做一个验证也抛显示异常。醉了。
                rediExcelList= MyCollectionUtil.removeLastEmpty(rediExcelList);//删掉尾部空白行
                b = BeanValidateUtil.vali2(rediExcelList,4+"");//TODO 待验证：这个地方为什么是从4开始？
                /*
                if (!b.isRelult()){//如果验证失败
                    String m=b.getAllString();
                    //response.setStatus(503);
                    AjaxSupport.sendFailText("fail",m);
                    return;
                }*/
            } catch (Exception e) {
                logger.error("处理Excel文件出现异常", e);
                AjaxSupport.sendFailText("Fail", "操作失败：无法读取Excel。<br />原因：" + e.getMessage());
                return;
            }finally {
                try {
                    is.close();
                } catch (Exception e2) {
                }
            }
            Asserts.assertTrue(b.isRelult(),b.getAllString());
            
            //取出自定义编号
            String[] defectInfoCodes = DomainCollectionsUtil.toOneFieldValues(rediExcelList,"defectInfoCode");
            DefectSuggestVO defectSuggest = new DefectSuggestVO();
            defectSuggest.setCustomNumbers(defectInfoCodes);
            //根据自定义编号查询未维修的缺陷点
            List<DefectInfoDTO> defectInfoList = defectInfoService.queryBySuggestVO(defectSuggest);
            //断言其来自同一个内检测任务
            assertSameInstTaskId(defectInfoList);
            
            String[] defectInfoIds = DomainCollectionsUtil.toOneFieldValues(defectInfoList,"defectId");
            List<String> defectInfoIdList = new ArrayList<String>(defectInfoIds.length);
            Collections.addAll(defectInfoIdList, defectInfoIds);
            //统计维修工作量
            RepairTaskWorkload repairTaskWorkload = defectInfoService.countWorkload(defectInfoIdList);
            //defectInfoList = DomainCodeInterceptor.newProxyInstance(defectInfoList);

            model.addAttribute("defectInfoList", defectInfoList);
            model.addAttribute("repairTaskWorkload", repairTaskWorkload);
            
        }

        String fromName = "fromPointName";
        String toName = "toPointName";
        model.addAttribute(fromName,request.getParameter(fromName));
        model.addAttribute(toName,request.getParameter(toName));
        model.addAttribute("fromPointMile",request.getParameter("fromPointMile"));
        model.addAttribute("toPointMile",request.getParameter("toPointMile"));
        
        String pipeLineName = request.getParameter("pipeLineName");//管道名称，只是为了还给页面做显示
        //String pipeSegmentName = request.getParameter("pipeSegmentName");//管段名称，只是为了还给页面做显示
        model.addAttribute("pipeLineName", pipeLineName);
        //model.addAttribute("pipeSegmentName", pipeSegmentName);
        
        AjaxSupport.sendSuccessText("success", model);
        
    }


    /**
     * 直接保存
     * /pbf/RepairTask/createOrUpdate2.json
     * 
     * name=维修任务名称
     * assemblyCompany=施工单位
     * pipeLineId=管道编号
     * pipeSegmentId=管段编号
     * planStartDate=开工时间
     * planCompletionDate=竣工时间
     * dataStated=20发布、03保存
     * 
     * coatRepair=防腐层修复_工作量
     * compositesRepair=复合材料补强修复_工作量
     * epoxySleeveRepair=钢质环氧套筒补强修复_工作量
     * atypeSleeveRepair=A型套筒补强修复_工作量
     * btypeSleeveRepair=B型套筒补强修复_工作量
     * pipeReplacement=换管_工作量
     * excavationVerification=开挖验证_工作量
     * otherRepairWf=其他修复流程_工作量
     * 
     * defectInfoId=缺陷点编号1
     * defectInfoId=缺陷点编号2
     * 
     * @param repairTask
     * @param defectInfoIds
     */
    @RequestMapping("/createOrUpdate2.json")
    @ResponseBody
    public void createOrUpdate2(RepairTask repairTask,RepairTaskWorkload repairTaskWorkload,@RequestParam("defectInfoId") String[] defectInfoIds) {
        
        fillRepairTaskWorkloadNullToZero(repairTaskWorkload);
        
        repairTaskService.createOrUpdate(repairTask,repairTaskWorkload, defectInfoIds);
        
        AjaxSupport.sendSuccessText("success", "");
    }
    
    /**
     * 修改维修任务数据状态
     *  用于发布任务任务的情况。
     * repairTaskId=维修任务编号1
     * repairTaskId=维修任务编号2
     * 
     * dataState=state20（可选参数传递，默认就是改成发布状态）
     * 
     * @param repairTaskIds
     * @param dataState
     */
    @RequestMapping("/updateDataState.json")
    @ResponseBody
    public void updateDataState(@RequestParam("repairTaskId") String[] repairTaskIds
            ,@RequestParam(value = "dataState",defaultValue = "state20")DefectStateEnum dataState
            ,ModelMap model) {
        
        int secc = repairTaskService.updateDataStated(repairTaskIds, dataState);
        model.addAttribute("count", repairTaskIds.length);
        model.addAttribute("successCount", secc);
        AjaxSupport.sendSuccessText("success", model);
    }
    

    /**
     * 修改维修任务的修复状态（用于关闭任务）
     * repairTaskId=维修任务编号1
     * repairTaskId=维修任务编号2
     * 
     * repairTaskStated=CLOSED（可选参数，默认就是改为关闭）
     * 
     * @param repairTaskIds
     * @param repairTaskStated
     */
    @RequestMapping("/updateRepairTaskStated.json")
    @ResponseBody
    public void updateRepairTaskStated(@RequestParam("repairTaskId") String[] repairTaskIds
            ,@RequestParam(value = "repairTaskStated",defaultValue = "ALREADY_REPAIR")RepairTaskStatedEnum repairTaskStated
            ,ModelMap model) {
        
        int secc = repairTaskService.updateRepairTaskStated(repairTaskIds, repairTaskStated);
        model.addAttribute("count", repairTaskIds.length);
        model.addAttribute("successCount", secc);
        AjaxSupport.sendSuccessText("success", model);
    }

    /**
     * 删除任务
     * 
     * @param repairTaskIds
     */
    @RequestMapping("/updateToDelete.json")
    @ResponseBody
    public void updateToDelete(@RequestParam("repairTaskId") String[] repairTaskIds,ModelMap model) {
        
        int secc = repairTaskService.updateToDelete(repairTaskIds);
        model.addAttribute("successCount", secc);
        model.addAttribute("count", repairTaskIds.length);
        AjaxSupport.sendSuccessText("success", model);
    }
    

    /*
    @RequestMapping("/createOrUpdate2.json")
    @ResponseBody
    public void toExcel() {

        String templateName="out/pipe_cross_template.xls";
        Workbook workbook=ReadExcel.readExcelTemplate(templateName);
        Workbook workbookFinal = WriteExcel.writeExcel(workbook,infoList,2, Lists.<String>newArrayList("priUuid"));
        DownLoadController.initExcelDownResponse(response,StringUtils.removeEnd(templateName,"Template"));
        DownLoadController.excelOut(response,workbookFinal);
        return;
    }
    */
    
    
    /**
     * 断言来自同一个内检测任务，如果不同，则断言异常。
     * 
     * @param defectInfoList
     */
    private void assertSameInstTaskId(List<DefectInfoDTO> defectInfoList){
        if(defectInfoList != null && defectInfoList.size() > 1){
            DefectInfoDTO defectInfo_base = defectInfoList.get(0);
            String defectInfoCode_base = defectInfo_base.getCode();
            String instTaskId_base = defectInfo_base.getInstTaskId();
            for (int i = 1; i < defectInfoList.size(); i++) {
                DefectInfoDTO defectInfo = defectInfoList.get(i);
                String defectInfoCode = defectInfo.getCode();
                Asserts.assertTrue(instTaskId_base.equals(defectInfo.getInstTaskId()), "编号为" + defectInfoCode + "与" + defectInfoCode_base + "不是来自同一内检测任务");
            }
        }
        
    }
    
    /**
     * 把NULL变成0，或许有更加靠谱的方法。
     * 
     * @param repairTaskWorkload
     */
    private void fillRepairTaskWorkloadNullToZero(RepairTaskWorkload repairTaskWorkload){
        
        BigDecimal coatRepair = repairTaskWorkload.getCoatRepair();
        if(coatRepair == null){
            repairTaskWorkload.setCoatRepair(BigDecimal.ZERO);
        }
        BigDecimal compositesRepair = repairTaskWorkload.getCompositesRepair();
        if(compositesRepair == null){
            repairTaskWorkload.setCompositesRepair(BigDecimal.ZERO);
        }
        BigDecimal epoxySleeveRepair = repairTaskWorkload.getEpoxySleeveRepair();
        if(epoxySleeveRepair == null){
            repairTaskWorkload.setEpoxySleeveRepair(BigDecimal.ZERO);
        }
        BigDecimal atypeSleeveRepair = repairTaskWorkload.getAtypeSleeveRepair();
        if(atypeSleeveRepair == null){
            repairTaskWorkload.setAtypeSleeveRepair(BigDecimal.ZERO);
        }
        BigDecimal btypeSleeveRepair = repairTaskWorkload.getBtypeSleeveRepair();
        if(btypeSleeveRepair == null){
            repairTaskWorkload.setBtypeSleeveRepair(BigDecimal.ZERO);
        }
        BigDecimal pipeReplacement = repairTaskWorkload.getPipeReplacement();
        if(pipeReplacement == null){
            repairTaskWorkload.setPipeReplacement(BigDecimal.ZERO);
        }
        BigDecimal excavationVerification = repairTaskWorkload.getExcavationVerification();
        if(excavationVerification == null){
            repairTaskWorkload.setExcavationVerification(BigDecimal.ZERO);
        }
        BigDecimal otherRepairWf = repairTaskWorkload.getOtherRepairWf();
        if(otherRepairWf == null){
            repairTaskWorkload.setOtherRepairWf(BigDecimal.ZERO);
        }
    }
    
    
    
    
    
    
}
